package de.ifi.lmu.snitzelhunt.view;

import java.util.ArrayList;

import de.ifi.lmu.snitzelhunt.R;
import de.ifi.lmu.snitzelhunt.basics.User;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ContactListViewAdapter extends ArrayAdapter<User> {
	private final Context context;
	private final ArrayList<User> values;

	private TextView userName;
	private TextView number;

	public ContactListViewAdapter(Context context, ArrayList<User> values) {
		super(context, R.layout.create_hunt_tasklist_layout, values);
		this.context = context;
		this.values = values;

		Log.i("ContactListView",
				"initialized with Userlist of size " + values.size());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.selected_users_list_layout,
				parent, false);

		Log.i("contactlistview", "updating listview");

		userName = (TextView) rowView.findViewById(R.id.userName);
		number = (TextView) rowView.findViewById(R.id.userCell);

		userName.setText(values.get(position).getName());
		number.setText(values.get(position).getCellNumber());

		return rowView;
	}

	@Override
	public int getCount() {
		return values.size();
	}

}
